import { Global, Module } from '@nestjs/common';
import { UserService } from './user.service';
import { UserController } from './user.controller';
import { UserEntity } from './entities/user.entity';
import { TypeOrmModule } from '@nestjs/typeorm';

import { JwtModule } from '@nestjs/jwt'; // 添加 JWT 模块
import { ConfigService } from '@nestjs/config';

const jwtModule = JwtModule.registerAsync({
  inject: [ConfigService],
  global: true,
  useFactory: async (configService: ConfigService) => {
    return {
      secret: configService.get('JWT_SECRET'),
      signOptions: {
        expiresIn: configService.get('JWT_EXPIRES_IN'),
        // },
        algorithm: 'HS384', // 更短的算法
        noTimestamp: true, // 去除不必要字段
      },
    };
  },
});

@Global()
@Module({
  imports: [TypeOrmModule.forFeature([UserEntity]), jwtModule],
  controllers: [UserController],
  providers: [UserService],
  exports: [UserService, jwtModule],
})
export class UserModule {}
